{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 基于MindQuantum的Shor算法\n",
    "\n",
    "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.png)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/mindquantum/zh_cn/mindspore_shor_algorithm.ipynb)&emsp;\n",
    "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.png)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/mindquantum/zh_cn/mindspore_shor_algorithm.py)&emsp;\n",
    "[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.png)](https://gitee.com/mindspore/docs/blob/master/docs/mindquantum/docs/source_zh_cn/shor_algorithm.ipynb)\n",
    "\n",
    "## Shor算法简介\n",
    "\n",
    "Shor算法在量子计算机上分解整数$N$的时间复杂度为$logN$，几乎是对已知最有效的经典因数分解算法的$e$指数级加速，这种加速有可能在量子计算机上中断如RSA的现代加密机制。\n",
    "\n",
    "## Shor算法基本思路\n",
    "\n",
    "Shor算法要解决的主要问题是：给定一个整数$N$，找出它的质因数。即对一个给定的较大数$N$在多项式时间内确定两个素因子 $p1$和$p2$满足$p1\\cdot p2=N$。 在介绍Shor算法步骤之前，先介绍一些数论知识。\n",
    "\n",
    "因子分解涉及到数论里的一些知识，可以将因子分解问题归结为函数\n",
    "\n",
    "$$\n",
    "f(x)=a^x\\ mod\\ N\n",
    "$$\n",
    "\n",
    "对于$a$的周期查找（$a$和$N$互质，否则通过调用$gcd(a,N)$就可以马上得到一个因子）。 由于函数$f(x)$存在周期$r$满足$f(x)=f(x+r)$。在这种情形下，就可得\n",
    "\n",
    "$$\n",
    "a^x=a^{x+r}\\ mod\\ N\\ \\ \\forall x\n",
    "$$\n",
    "\n",
    "令$x=0$，得到$a^r=1+qN$，其中$q$为某一整数，即\n",
    "\n",
    "$$\n",
    "a^r-1=(a^{r/2}-1)(a^{r/2}+1)=qN\n",
    "$$\n",
    "\n",
    "这也表明对于$N$使用$gcd$就可以找到其因子。\n",
    "\n",
    "因此，Shor算法的核心在于，将大数分解的问题转化为找周期的问题。由于量子计算可以利用叠加态进行并行计算，因此通过量子算法我们可以很快地找到函数$f(x)$的周期$r$（具体的原理和步骤请参考本文档中的`周期查找算法`）。总的来说，我们需要在量子线路中实现$f(|x\\rangle)=a^{|x\\rangle}\\ mod\\ N$的函数运算，可以构造一个酉矩阵$U_{a,N}$使得$U_{a,N}|x\\rangle |y\\rangle \\rightarrow |x\\rangle |y \\oplus f(x) \\rangle$，然后利用量子傅立叶变换我们就可以找到周期$r$满足$a^r\\equiv 1(\\ mod\\ N)$。\n",
    "\n",
    "下面以 $N=15$为例，介绍Shor算法在因子分解的步骤：\n",
    "\n",
    "1. 选择一个任意的数字，比如$a=2(<15)$\n",
    "\n",
    "2. 求最大公约数，$gcd(a,N)=gcd(2,15)=1$\n",
    "\n",
    "3. 找函数$f(x)=a^x\\ mod\\ N$的周期，使得$f(x+r)=f(x)$\n",
    "\n",
    "4. 通过量子电路图运算得到$r=4$\n",
    "\n",
    "5. 求最大公约数，$\\gcd(a^{r/2}+1,N)=\\gcd(5,15)=5$\n",
    "\n",
    "6. 求最大公约数，$\\gcd(a^{r/2}-1,N)=\\gcd(3,15)=3$\n",
    "\n",
    "7. $N=15$分解得到的质数结果为3和5，分解完成。\n",
    "\n",
    "Shor算法的量子电路如下图所示：\n",
    "\n",
    "![shor's algorithm circuit](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindquantum/docs/source_zh_cn/images/shor_algorithm_circuit.png)\n",
    "\n",
    "## 通过MindQuantum实现Shor算法\n",
    "\n",
    "首先，导入需要用到的模块。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#pylint: disable=W0611\n",
    "import numpy as np\n",
    "from fractions import Fraction\n",
    "import mindquantum as mq\n",
    "from mindquantum.core.gates import X, Z, H, UnivMathGate, Measure\n",
    "from mindquantum.core.circuit import Circuit, controlled, UN\n",
    "from mindquantum.algorithm.library import qft\n",
    "from mindquantum.simulator import Simulator"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "从Shor算法的基本思路我们可以看出，Shor算法最核心的部分就在于由量子计算机处理的周期查找算法，而周期查找算法中最困难的地方就是将态$|x\\rangle |y\\rangle$变为$|x\\rangle |y \\oplus f(x) \\rangle$的算子$U$，这个算子的量子线路构造较为复杂，因此以下我们先通过经典计算机算出算子$U$并当作一个Oracle，以便本文档可以整体而直观地演示出Shor算法。\n",
    "\n",
    "### 构造Oracle\n",
    "\n",
    "该Oracle的构造方法原本十分简单，只需3步：\n",
    "\n",
    "1. 将变换前所有可能的$x$进行穷举（从$0$到$N-1$共有$N$个数），并一一算出对应的$f(x)=a^x\\ mod\\ N$。\n",
    "2. 对每一个$x$，我们都可以写出变换前的态$|x\\rangle |0\\rangle$和变换后的态$|x\\rangle |f(x)\\rangle$的矩阵表示，将它们进行外乘即可得到每一个$x$对应的变换矩阵，然后将所有矩阵求和即得到算子$U$的矩阵表示，即\n",
    "\n",
    "    $$\n",
    "    U=\\sum_{x=0}^{N-1} |x\\rangle |0\\rangle \\langle x|\\langle f(x)|\n",
    "    $$\n",
    "\n",
    "3. 用矩阵$U$生成自定义门。\n",
    "\n",
    "举例：$N=15,a=2$的情况，我们可以得到$x$与$f(x)$:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x:  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n",
      "f(x):  [1, 2, 4, 8, 1, 2, 4, 8, 1, 2, 4, 8, 1, 2, 4, 8]\n"
     ]
    }
   ],
   "source": [
    "q = 4  # 比特数\n",
    "N = 15\n",
    "a = 2\n",
    "x = []\n",
    "f = []\n",
    "for i in range(2**q):\n",
    "    x.append(i)\n",
    "    f.append(a**i % N)\n",
    "print('x: ', x)\n",
    "print('f(x): ', f)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "然后计算$|0\\rangle |0\\rangle \\langle 0| \\langle 1|+|1\\rangle |0\\rangle \\langle 1| \\langle 2|+|2\\rangle |0\\rangle \\langle 2|\\langle 4|+...$即得到变换$U$的矩阵表示。其中$|0\\rangle |0\\rangle$、$|0\\rangle |1\\rangle$、$|0\\rangle |2\\rangle$...可以表示为相互正交的、含有256个元素的列向量，其中只有一个元素是1，其余为0。例如$|0\\rangle |0\\rangle$是第一个元素是1，$|0\\rangle |1\\rangle$是第二个元素是1，$|1\\rangle |0\\rangle$是第17个元素为1，以此类推。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "但是，由于MindQuantum当前版本的Simulator对自定义门的比特数做出了限制（不能大于5比特），而即使分解最小的非偶质因数整数15=3*5也要至少8个比特，因此构造此Oracle使用了妥协而复杂得多的办法，即寄存器1（4个比特）作为控制比特，在寄存器2（4个比特）作用每一个$x$对应的变换$T_x$：\n",
    "\n",
    "$$\n",
    "T_x|x\\rangle \\rightarrow |a^x\\ mod\\ N\\rangle\n",
    "$$\n",
    "\n",
    "每一个$T_x$都受寄存器1控制，只当寄存器1中存储的数为$x$时才作用，最后一共有$N$个门，包括这$N$个门的整个线路对应于算子$U$。需要注意的是，$T_x$自身不是一个门，因为它不是一个可逆操作，因此仅当寄存器2处于$|0\\rangle$态时，该Oracle才能给出正确的输出。\n",
    "\n",
    "下面是妥协后的Oracle构造方法："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def U_operator(N, a, register1, register2):\n",
    "    Q = 2**len(register1)\n",
    "    x = []\n",
    "    f = []\n",
    "    for i in range(Q):\n",
    "        x.append(i)\n",
    "        f.append(a**i % N)  # 计算f(x)\n",
    "\n",
    "    # 创建量子态|register2>的矩阵表示\n",
    "    vector = np.zeros((Q, Q))\n",
    "    for i in range(Q):\n",
    "        vector[i, i] = 1\n",
    "\n",
    "    T = []\n",
    "    for i in range(Q):\n",
    "        matrix = np.outer(vector[f[i]], vector[0])  # 计算映射Tx的矩阵\n",
    "        T.append(UnivMathGate(f'f({i})', matrix))  # 用变换矩阵构造Tx“门”\n",
    "\n",
    "    # 创建控制线路，得到算子U。对于每个Tx“门”，都受寄存器1中所有比特控制，其对应x的二进制中比特位是1的是正常控制节点，比特位是0的则要在控制节点两侧作用X门，翻转控制位\n",
    "    circuit = Circuit()\n",
    "    for i in range(Q):\n",
    "        bin_x = bin(x[i])[2:]  # 将x转换为二进制\n",
    "        flip_control_qubit = list(range(len(register1)))  # 初始化需要作用X门的比特的list\n",
    "\n",
    "        for j in range(len(bin_x)):\n",
    "            if bin_x[len(bin_x) - j - 1] == '1':  # 获得x的二进制中是‘1’的比特\n",
    "                flip_control_qubit.remove(j)  # 从list中删除不需要作用X门的控制比特\n",
    "\n",
    "        circuit.barrier()  # 添加barrier\n",
    "        circuit += UN(X, flip_control_qubit)  # 在控制节点前作用X门\n",
    "        circuit += T[x[i]].on(register2, list(register1))  # 给Tx“门”接上控制比特\n",
    "        circuit += UN(X, flip_control_qubit)  # 在控制节点后作用X门\n",
    "\n",
    "    return circuit"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "现在，`U_operator()`函数就可以对寄存器1中的量子态$|x\\rangle$进行指数模运算，并将得到的结果$a^{|x\\rangle}\\ mod\\ N$存入寄存器2。\n",
    "\n",
    "举例：$N=15,a=2$的情况，我们构造出对应的$U$算子，并验证它是否能正确得到结果（寄存器1和寄存器2各需要4个比特来存储$x$和$f(x)$）："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1¦00010100⟩\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": "<div class=\"nb-html-output output_area\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"4196.8\" height=\"500\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<rect x=\"0\" y=\"0\" width=\"4196.8\" height=\"500\" fill=\"#ffffff\" />\n<text x=\"20.0\" y=\"40.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq0:\n </text>\n<text x=\"20.0\" y=\"100.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq1:\n </text>\n<text x=\"20.0\" y=\"160.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq2:\n </text>\n<text x=\"20.0\" y=\"220.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq3:\n </text>\n<text x=\"20.0\" y=\"280.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq4:\n </text>\n<text x=\"20.0\" y=\"340.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq5:\n </text>\n<text x=\"20.0\" y=\"400.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq6:\n </text>\n<text x=\"20.0\" y=\"460.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq7:\n </text>\n<line x1=\"48.8\" x2=\"4176.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"4176.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"4176.8\" y1=\"160.0\" y2=\"160.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"4176.8\" y1=\"220.0\" y2=\"220.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"4176.8\" y1=\"280.0\" y2=\"280.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"4176.8\" y1=\"340.0\" y2=\"340.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"4176.8\" y1=\"400.0\" y2=\"400.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"4176.8\" y1=\"460.0\" y2=\"460.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n\n<rect x=\"72.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"92.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"132.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"172.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"192.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"172.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"192.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"172.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"192.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"172.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"192.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"272.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"272.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"272.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"272.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"272.8\" x2=\"272.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"232.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"272.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(0)\n </text>\n\n\n<rect x=\"332.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"352.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"332.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"352.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"332.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"352.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"332.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"352.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"392.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"432.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"452.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"432.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"452.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"432.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"452.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"532.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"532.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"532.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"532.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"532.8\" x2=\"532.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"492.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"532.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(1)\n </text>\n\n\n<rect x=\"592.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"612.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"592.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"612.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"592.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"612.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"652.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"692.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"712.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"692.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"712.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"692.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"712.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"792.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"792.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"792.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"792.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"792.8\" x2=\"792.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"752.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"792.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(2)\n </text>\n\n\n<rect x=\"852.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"872.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"852.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"872.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"852.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"872.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"912.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"952.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"972.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"952.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"972.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"1052.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1052.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1052.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1052.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"1052.8\" x2=\"1052.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"1012.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1052.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(3)\n </text>\n\n\n<rect x=\"1112.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1132.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1112.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1132.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"1172.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"1212.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1232.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1212.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1232.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1212.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1232.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"1312.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1312.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1312.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1312.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"1312.8\" x2=\"1312.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"1272.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1312.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(4)\n </text>\n\n\n<rect x=\"1372.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1392.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1372.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1392.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1372.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1392.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"1432.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"1472.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1492.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1472.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1492.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"1572.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1572.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1572.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1572.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"1572.8\" x2=\"1572.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"1532.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1572.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(5)\n </text>\n\n\n<rect x=\"1632.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1652.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1632.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1652.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"1692.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"1732.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1752.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1732.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1752.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"1832.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1832.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1832.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1832.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"1832.8\" x2=\"1832.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"1792.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1832.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(6)\n </text>\n\n\n<rect x=\"1892.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1912.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1892.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1912.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"1952.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"1992.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2012.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"2092.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2092.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2092.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2092.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"2092.8\" x2=\"2092.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"2052.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2092.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(7)\n </text>\n\n\n<rect x=\"2152.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2172.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"2212.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"2252.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2272.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2252.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2272.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2252.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2272.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"2352.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2352.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2352.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2352.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"2352.8\" x2=\"2352.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"2312.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2352.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(8)\n </text>\n\n\n<rect x=\"2412.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2432.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2412.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2432.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2412.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2432.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"2472.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"2512.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2532.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2512.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2532.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"2612.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2612.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2612.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2612.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"2612.8\" x2=\"2612.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"2572.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2612.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(9)\n </text>\n\n\n<rect x=\"2672.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2692.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2672.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2692.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"2732.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"2772.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2792.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2772.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2792.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"2872.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2872.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2872.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2872.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"2872.8\" x2=\"2872.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"2832.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2872.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(10)\n </text>\n\n\n<rect x=\"2932.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2952.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2932.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2952.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"2992.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"3032.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3052.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"3132.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3132.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3132.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3132.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"3132.8\" x2=\"3132.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"3092.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3132.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(11)\n </text>\n\n\n<rect x=\"3192.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3212.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"3252.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"3292.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3312.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"3292.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3312.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"3392.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3392.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3392.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3392.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"3392.8\" x2=\"3392.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"3352.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3392.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(12)\n </text>\n\n\n<rect x=\"3452.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3472.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"3452.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3472.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"3512.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"3552.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3572.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"3652.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3652.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3652.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3652.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"3652.8\" x2=\"3652.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"3612.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3652.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(13)\n </text>\n\n\n<rect x=\"3712.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3732.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"3772.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"3812.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3832.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"3912.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3912.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3912.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3912.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"3912.8\" x2=\"3912.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"3872.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3912.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(14)\n </text>\n\n\n<rect x=\"3972.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3992.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"4032.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n<circle cx=\"4112.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"4112.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"4112.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"4112.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"4112.8\" x2=\"4112.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"4072.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"4112.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(15)\n </text>\n\n</svg></div>",
      "text/plain": [
       "<mindquantum.io.display.circuit_svg_drawer.SVGCircuit at 0x7f61ec6f5400>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pylint: disable=W0104\n",
    "register1 = range(4)\n",
    "register2 = range(4, 8)\n",
    "circuit = Circuit(X.on(2))  # 创建线路，使输入态为|0100⟩|0000⟩，即x=8，|8⟩|0⟩\n",
    "circuit += U_operator(15, 2, register1, register2)  # 作用U算子\n",
    "\n",
    "print(circuit.get_qs(ket=True))  # 打印末态\n",
    "circuit.svg() #打印线路"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "寄存器1中结果为0100，寄存器2中结果为0001，先前我们已经算出了$f(8)=2^8\\ mod\\ 15=1$，因此输出结果正确。线路虽然看起来较为复杂，实际上就是16个受控4比特门依次作用而已，前四个比特上的`X`门用途为翻转控制位。\n",
    "\n",
    "接下来我们需要实现周期查找算法。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 周期查找算法\n",
    "\n",
    "1. 在寄存器1中我们需要$q>log_2 N$个比特来记录自变量$x \\in [0,N-1]$的二进制数，寄存器2中同样需要$q$个比特来记录$f(x)=a^x\\ mod\\ N\\ \\in [0,N-1]$的二进制数。此时寄存器1和寄存器2分别能记录$[0,Q-1]$的整数,其中$Q=2^q>N$。\n",
    "2. 对寄存器1中的所有比特作用`Hadamard`门，此时寄存器1中的比特处于$[0,Q-1]$中所有整数的均匀叠加态\n",
    "\n",
    "    $$\n",
    "    |\\psi\\rangle=\\sum_{x=0}^{Q-1}|x\\rangle\n",
    "    $$\n",
    "\n",
    "3. 对寄存器1存储的态$|\\psi\\rangle$做函数运算$a^{|\\psi\\rangle}\\ mod\\ N$，并将结果存入寄存器2，此步骤由先前构造的U_operator完成。由于直接对叠加态$|\\psi\\rangle$进行运算，此步骤只需一步完成，体现了量子计算的优势————并行计算。此时线路中存储的态是纠缠态，可以表示为\n",
    "\n",
    "    $$\n",
    "    \\sum_{x=0}^{Q-1}|x\\rangle|f(x)\\rangle=\\sum_{i=0}^{r-1}(|i\\rangle+|i+r\\rangle+|i+2r\\rangle+...)\\ |f(i)\\rangle\n",
    "    $$\n",
    "\n",
    "4. 对寄存器1做傅立叶逆变换，此变换使用一个$Q$次单位根$\\omega^{2\\pi i/Q}$，会将任意给定态$|x\\rangle$的振幅平均分布在$Q$个$|y\\rangle$态上。而如步骤3中显示的，寄存器1中$|i\\rangle$与$|i+r\\rangle$等态均与寄存器2中同一个态$|f(i)\\rangle$相纠缠，因此会发生量子干涉，最终使得当单位矢量$\\omega^{2\\pi iry/Q}$越接近1（指向正实数轴）时，测量得到态$|y\\rangle$的概率越大。换句话说，我们测得的态$|y\\rangle$，有很大概率使得$\\frac{ry}{Q}$接近某一整数$c$。更详尽的数学描述可以参考链接：https://zh.wikipedia.org/wiki/秀爾演算法 中的“量子部分：周期查找子程序”。\n",
    "5. 测量寄存器1，得到二进制串。将二进制数转化为十进制数$y$，此时$\\frac{y}{Q}\\sim\\frac{c}{r}$，其中$c$是未知整数。通过连分数分解法计算$\\frac{y}{Q}$逼近的不可约分数（分母不大于$N$），取其分母即得到周期$r$。但是，在分母小于$N$的不可约分数中可能存在比$\\frac{c}{r}$更逼近$\\frac{y}{Q}$的分数，或是$c$与$r$存在公因数，则得到的$r$会是真正函数周期的因数，此时计算失败，重新计算。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "举例：还是用$N=15,a=2$的例子，在`构造Oracle`中我们把每一个$f(x)$都算了出来，从中可以直接看出函数周期为4。现在我们可以搭建对应的周期查找线路，并进行100次模拟，看看会得到哪些结果。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": "<div class=\"nb-html-output output_area\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"5056.8\" height=\"500\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<rect x=\"0\" y=\"0\" width=\"5056.8\" height=\"500\" fill=\"#ffffff\" />\n<text x=\"20.0\" y=\"40.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq0:\n </text>\n<text x=\"20.0\" y=\"100.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq1:\n </text>\n<text x=\"20.0\" y=\"160.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq2:\n </text>\n<text x=\"20.0\" y=\"220.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq3:\n </text>\n<text x=\"20.0\" y=\"280.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq4:\n </text>\n<text x=\"20.0\" y=\"340.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq5:\n </text>\n<text x=\"20.0\" y=\"400.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq6:\n </text>\n<text x=\"20.0\" y=\"460.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq7:\n </text>\n<line x1=\"48.8\" x2=\"5036.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"5036.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"5036.8\" y1=\"160.0\" y2=\"160.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"5036.8\" y1=\"220.0\" y2=\"220.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"5036.8\" y1=\"280.0\" y2=\"280.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"5036.8\" y1=\"340.0\" y2=\"340.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"5036.8\" y1=\"400.0\" y2=\"400.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"5036.8\" y1=\"460.0\" y2=\"460.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n\n<rect x=\"72.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"92.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nH\n </text>\n\n\n<rect x=\"72.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"92.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nH\n </text>\n\n\n<rect x=\"72.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"92.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nH\n </text>\n\n\n<rect x=\"72.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"92.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nH\n </text>\n\n<rect x=\"132.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"172.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"192.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"172.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"192.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"172.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"192.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"172.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"192.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"272.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"272.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"272.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"272.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"272.8\" x2=\"272.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"232.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"272.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(0)\n </text>\n\n\n<rect x=\"332.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"352.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"332.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"352.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"332.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"352.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"332.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"352.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"392.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"432.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"452.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"432.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"452.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"432.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"452.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"532.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"532.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"532.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"532.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"532.8\" x2=\"532.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"492.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"532.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(1)\n </text>\n\n\n<rect x=\"592.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"612.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"592.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"612.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"592.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"612.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"652.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"692.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"712.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"692.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"712.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"692.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"712.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"792.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"792.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"792.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"792.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"792.8\" x2=\"792.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"752.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"792.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(2)\n </text>\n\n\n<rect x=\"852.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"872.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"852.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"872.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"852.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"872.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"912.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"952.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"972.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"952.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"972.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"1052.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1052.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1052.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1052.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"1052.8\" x2=\"1052.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"1012.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1052.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(3)\n </text>\n\n\n<rect x=\"1112.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1132.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1112.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1132.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"1172.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"1212.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1232.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1212.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1232.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1212.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1232.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"1312.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1312.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1312.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1312.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"1312.8\" x2=\"1312.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"1272.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1312.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(4)\n </text>\n\n\n<rect x=\"1372.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1392.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1372.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1392.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1372.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1392.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"1432.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"1472.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1492.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1472.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1492.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"1572.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1572.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1572.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1572.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"1572.8\" x2=\"1572.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"1532.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1572.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(5)\n </text>\n\n\n<rect x=\"1632.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1652.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1632.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1652.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"1692.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"1732.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1752.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1732.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1752.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"1832.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1832.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1832.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"1832.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"1832.8\" x2=\"1832.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"1792.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1832.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(6)\n </text>\n\n\n<rect x=\"1892.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1912.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"1892.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"1912.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"1952.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"1992.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2012.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"2092.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2092.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2092.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2092.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"2092.8\" x2=\"2092.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"2052.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2092.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(7)\n </text>\n\n\n<rect x=\"2152.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2172.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"2212.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"2252.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2272.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2252.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2272.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2252.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2272.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"2352.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2352.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2352.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2352.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"2352.8\" x2=\"2352.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"2312.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2352.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(8)\n </text>\n\n\n<rect x=\"2412.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2432.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2412.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2432.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2412.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2432.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"2472.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"2512.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2532.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2512.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2532.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"2612.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2612.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2612.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2612.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"2612.8\" x2=\"2612.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"2572.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2612.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(9)\n </text>\n\n\n<rect x=\"2672.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2692.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2672.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2692.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"2732.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"2772.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2792.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2772.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2792.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"2872.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2872.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2872.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"2872.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"2872.8\" x2=\"2872.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"2832.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2872.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(10)\n </text>\n\n\n<rect x=\"2932.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2952.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"2932.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"2952.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"2992.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"3032.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3052.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"3132.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3132.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3132.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3132.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"3132.8\" x2=\"3132.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"3092.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3132.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(11)\n </text>\n\n\n<rect x=\"3192.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3212.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"3252.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"3292.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3312.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"3292.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3312.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"3392.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3392.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3392.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3392.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"3392.8\" x2=\"3392.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"3352.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3392.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(12)\n </text>\n\n\n<rect x=\"3452.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3472.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n\n<rect x=\"3452.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3472.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"3512.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"3552.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3572.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"3652.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3652.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3652.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3652.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"3652.8\" x2=\"3652.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"3612.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3652.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(13)\n </text>\n\n\n<rect x=\"3712.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3732.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"3772.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n\n<rect x=\"3812.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3832.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<circle cx=\"3912.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3912.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3912.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"3912.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"3912.8\" x2=\"3912.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"3872.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3912.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(14)\n </text>\n\n\n<rect x=\"3972.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"3992.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nX\n </text>\n\n<rect x=\"4032.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n<circle cx=\"4112.8\" cy=\"40.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"4112.8\" cy=\"100.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"4112.8\" cy=\"160.0\" r=\"4\" fill=\"#5e7ce0\" />\n<circle cx=\"4112.8\" cy=\"220.0\" r=\"4\" fill=\"#5e7ce0\" />\n<line x1=\"4112.8\" x2=\"4112.8\" y1=\"40.0\" y2=\"280.0\" stroke=\"#5e7ce0\" stroke-width=\"3\" />\n<rect x=\"4072.8\" y=\"260.0\" width=\"80.0\" height=\"220\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"4112.8\" y=\"370.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nf(15)\n </text>\n\n<rect x=\"4172.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n<line x1=\"4232.8\" x2=\"4232.8\" y1=\"80.0\" y2=\"180.0\" stroke-width=\"3\" stroke=\"#16acff\" />\n\n<rect x=\"4212.8\" y=\"80.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" fill=\"#16acff\" fill-opacity=\"1\" stroke=\"#ffffff\" stroke-width=\"0\" />\n<path d=\"M 4223.2 96.31384387633061 L 4228.0 88.0 L 4232.8 96.31384387633061 L 4229.4400000000005 96.31384387633061 L 4229.4400000000005 112.0 L 4226.56 112.0 L 4226.56 96.31384387633061 Z\" fill=\"#ffffff\" />\n<path d=\"M 4242.400000000001 103.68615612366939 L 4237.6 112.0 L 4232.8 103.68615612366939 L 4236.16 103.68615612366939 L 4236.16 88.0 L 4239.04 88.0 L 4239.04 103.68615612366939 Z\" fill=\"#ffffff\" />\n<rect x=\"4212.8\" y=\"140.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" fill=\"#16acff\" fill-opacity=\"1\" stroke=\"#ffffff\" stroke-width=\"0\" />\n<path d=\"M 4223.2 156.31384387633062 L 4228.0 148.0 L 4232.8 156.31384387633062 L 4229.4400000000005 156.31384387633062 L 4229.4400000000005 172.0 L 4226.56 172.0 L 4226.56 156.31384387633062 Z\" fill=\"#ffffff\" />\n<path d=\"M 4242.400000000001 163.68615612366938 L 4237.6 172.0 L 4232.8 163.68615612366938 L 4236.16 163.68615612366938 L 4236.16 148.0 L 4239.04 148.0 L 4239.04 163.68615612366938 Z\" fill=\"#ffffff\" />\n<line x1=\"4292.8\" x2=\"4292.8\" y1=\"20.0\" y2=\"240.0\" stroke-width=\"3\" stroke=\"#16acff\" />\n\n<rect x=\"4272.8\" y=\"20.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" fill=\"#16acff\" fill-opacity=\"1\" stroke=\"#ffffff\" stroke-width=\"0\" />\n<path d=\"M 4283.2 36.31384387633061 L 4288.0 28.0 L 4292.8 36.31384387633061 L 4289.4400000000005 36.31384387633061 L 4289.4400000000005 52.0 L 4286.56 52.0 L 4286.56 36.31384387633061 Z\" fill=\"#ffffff\" />\n<path d=\"M 4302.400000000001 43.68615612366939 L 4297.6 52.0 L 4292.8 43.68615612366939 L 4296.16 43.68615612366939 L 4296.16 28.0 L 4299.04 28.0 L 4299.04 43.68615612366939 Z\" fill=\"#ffffff\" />\n<rect x=\"4272.8\" y=\"200.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" fill=\"#16acff\" fill-opacity=\"1\" stroke=\"#ffffff\" stroke-width=\"0\" />\n<path d=\"M 4283.2 216.31384387633062 L 4288.0 208.0 L 4292.8 216.31384387633062 L 4289.4400000000005 216.31384387633062 L 4289.4400000000005 232.0 L 4286.56 232.0 L 4286.56 216.31384387633062 Z\" fill=\"#ffffff\" />\n<path d=\"M 4302.400000000001 223.68615612366938 L 4297.6 232.0 L 4292.8 223.68615612366938 L 4296.16 223.68615612366938 L 4296.16 208.0 L 4299.04 208.0 L 4299.04 223.68615612366938 Z\" fill=\"#ffffff\" />\n\n<rect x=\"4332.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"4352.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nH\n </text>\n\n<circle cx=\"4412.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" />\n<line x1=\"4412.8\" x2=\"4412.8\" y1=\"40.0\" y2=\"100.0\" stroke=\"#fac209\" stroke-width=\"3\" />\n<rect x=\"4392.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" />\n<text x=\"4412.8\" y=\"96.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nPS\n </text>\n<text x=\"4412.8\" y=\"112.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\n-π/2\n </text>\n\n\n<rect x=\"4452.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"4472.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nH\n </text>\n\n<circle cx=\"4532.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" />\n<line x1=\"4532.8\" x2=\"4532.8\" y1=\"40.0\" y2=\"160.0\" stroke=\"#fac209\" stroke-width=\"3\" />\n<rect x=\"4512.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" />\n<text x=\"4532.8\" y=\"156.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nPS\n </text>\n<text x=\"4532.8\" y=\"172.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\n-π/4\n </text>\n\n<circle cx=\"4592.8\" cy=\"100.0\" r=\"4\" fill=\"#fac209\" />\n<line x1=\"4592.8\" x2=\"4592.8\" y1=\"100.0\" y2=\"160.0\" stroke=\"#fac209\" stroke-width=\"3\" />\n<rect x=\"4572.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" />\n<text x=\"4592.8\" y=\"156.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nPS\n </text>\n<text x=\"4592.8\" y=\"172.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\n-π/2\n </text>\n\n\n<rect x=\"4632.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"4652.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nH\n </text>\n\n<circle cx=\"4712.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" />\n<line x1=\"4712.8\" x2=\"4712.8\" y1=\"40.0\" y2=\"220.0\" stroke=\"#fac209\" stroke-width=\"3\" />\n<rect x=\"4692.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" />\n<text x=\"4712.8\" y=\"216.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nPS\n </text>\n<text x=\"4712.8\" y=\"232.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\n-π/8\n </text>\n\n<circle cx=\"4772.8\" cy=\"100.0\" r=\"4\" fill=\"#fac209\" />\n<line x1=\"4772.8\" x2=\"4772.8\" y1=\"100.0\" y2=\"220.0\" stroke=\"#fac209\" stroke-width=\"3\" />\n<rect x=\"4752.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" />\n<text x=\"4772.8\" y=\"216.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nPS\n </text>\n<text x=\"4772.8\" y=\"232.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\n-π/4\n </text>\n\n<circle cx=\"4832.8\" cy=\"160.0\" r=\"4\" fill=\"#fac209\" />\n<line x1=\"4832.8\" x2=\"4832.8\" y1=\"160.0\" y2=\"220.0\" stroke=\"#fac209\" stroke-width=\"3\" />\n<rect x=\"4812.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" />\n<text x=\"4832.8\" y=\"216.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nPS\n </text>\n<text x=\"4832.8\" y=\"232.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\n-π/2\n </text>\n\n\n<rect x=\"4872.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"4892.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nH\n </text>\n\n<rect x=\"4932.8\" y=\"20.0\" width=\"20\" height=\"460\" fill=\"gray\" fill-opacity=\"0.8\" />\n<rect x=\"4972.8\" y=\"20.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#ff7272\" fill-opacity=\"1\" />\n<circle cx=\"4992.8\" cy=\"50.4\" r=\"1.6\" fill=\"#ffffff\" />\n<path d=\"M 4980.0 50.4 A 12.8 12.8 0 0 1 5005.6 50.4\" stroke=\"#ffffff\" stroke-width=\"2.4000000000000004\" fill-opacity=\"0\" />\n<path d=\"M 4996.901848317486 33.93539030917347 L 5005.215692193817 29.135390309173467 L 5005.215692193817 38.73539030917347 L 5001.890154643284 36.815390309173466 L 4994.04707658145 50.4 L 4992.384307806184 49.44 L 5000.227385868018 35.85539030917347 Z\" fill=\"#ffffff\" />\n<rect x=\"4972.8\" y=\"80.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#ff7272\" fill-opacity=\"1\" />\n<circle cx=\"4992.8\" cy=\"110.4\" r=\"1.6\" fill=\"#ffffff\" />\n<path d=\"M 4980.0 110.4 A 12.8 12.8 0 0 1 5005.6 110.4\" stroke=\"#ffffff\" stroke-width=\"2.4000000000000004\" fill-opacity=\"0\" />\n<path d=\"M 4996.901848317486 93.93539030917347 L 5005.215692193817 89.13539030917347 L 5005.215692193817 98.73539030917347 L 5001.890154643284 96.81539030917347 L 4994.04707658145 110.4 L 4992.384307806184 109.44 L 5000.227385868018 95.85539030917347 Z\" fill=\"#ffffff\" />\n<rect x=\"4972.8\" y=\"140.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#ff7272\" fill-opacity=\"1\" />\n<circle cx=\"4992.8\" cy=\"170.4\" r=\"1.6\" fill=\"#ffffff\" />\n<path d=\"M 4980.0 170.4 A 12.8 12.8 0 0 1 5005.6 170.4\" stroke=\"#ffffff\" stroke-width=\"2.4000000000000004\" fill-opacity=\"0\" />\n<path d=\"M 4996.901848317486 153.93539030917347 L 5005.215692193817 149.13539030917346 L 5005.215692193817 158.73539030917345 L 5001.890154643284 156.81539030917347 L 4994.04707658145 170.4 L 4992.384307806184 169.44 L 5000.227385868018 155.85539030917346 Z\" fill=\"#ffffff\" />\n<rect x=\"4972.8\" y=\"200.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#ff7272\" fill-opacity=\"1\" />\n<circle cx=\"4992.8\" cy=\"230.4\" r=\"1.6\" fill=\"#ffffff\" />\n<path d=\"M 4980.0 230.4 A 12.8 12.8 0 0 1 5005.6 230.4\" stroke=\"#ffffff\" stroke-width=\"2.4000000000000004\" fill-opacity=\"0\" />\n<path d=\"M 4996.901848317486 213.93539030917347 L 5005.215692193817 209.13539030917346 L 5005.215692193817 218.73539030917345 L 5001.890154643284 216.81539030917347 L 4994.04707658145 230.4 L 4992.384307806184 229.44 L 5000.227385868018 215.85539030917346 Z\" fill=\"#ffffff\" />\n</svg></div>",
      "text/plain": [
       "<mindquantum.io.display.circuit_svg_drawer.SVGCircuit at 0x7f61a459b0a0>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pylint: disable=W0104\n",
    "circuit = Circuit()  # 创建量子线路\n",
    "register1 = range(4)  # 设置前4个比特为寄存器1\n",
    "register2 = range(4, 8)  # 设置后4个比特为寄存器2\n",
    "\n",
    "circuit += UN(H, register1)  # 对寄存器1中的所有比特作用H门\n",
    "\n",
    "# 对寄存器1做模乘运算，并将结果存入寄存器2，该操作由一个大的U门完成\n",
    "circuit += U_operator(15, 2, register1, register2)\n",
    "\n",
    "circuit.barrier()  # 添加barrier\n",
    "circuit += qft(register1[::-1]).hermitian()  # 对寄存器1做傅立叶逆变换，须注意傅立叶变换作用的比特顺序，在这里需要反序\n",
    "circuit.barrier()  # 添加barrier\n",
    "circuit += UN(Measure(), register1)  # 测量寄存器1\n",
    "\n",
    "circuit.svg()  # 画出线路图"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "从线路图我们可以很直观地看到，整个周期查找线路由四部分组成：产生叠加态$\\rightarrow$函数运算$\\rightarrow$傅立叶逆变换$\\rightarrow$测量。\n",
    "\n",
    "接下来运行该线路100次，观察测量结果。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": "<div class=\"nb-html-output output_area\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"422.8\" height=\"207.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<rect x=\"0\" y=\"0\" width=\"422.8\" height=\"207.0\" fill=\"#ffffff\" />\n<text x=\"10\" y=\"17.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" >\nShots:\n 100\n </text>\n<text x=\"10\" y=\"31.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" >\nKeys: q0 q1 q2 q3\n </text>\n<line x1=\"52.8\" x2=\"412.8\" y1=\"62.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"52.8\" x2=\"52.8\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"54.8\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.0\n </text>\n<line x1=\"52.8\" x2=\"52.8\" y1=\"62.0\" y2=\"197.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"112.8\" x2=\"112.8\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"114.8\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.06\n </text>\n<line x1=\"112.8\" x2=\"112.8\" y1=\"62.0\" y2=\"197.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<line x1=\"172.8\" x2=\"172.8\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"174.8\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.12\n </text>\n<line x1=\"172.8\" x2=\"172.8\" y1=\"62.0\" y2=\"197.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<line x1=\"232.8\" x2=\"232.8\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"234.8\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.18\n </text>\n<line x1=\"232.8\" x2=\"232.8\" y1=\"62.0\" y2=\"197.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<line x1=\"292.8\" x2=\"292.8\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"294.8\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.24\n </text>\n<line x1=\"292.8\" x2=\"292.8\" y1=\"62.0\" y2=\"197.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<line x1=\"352.8\" x2=\"352.8\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"354.8\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.3\n </text>\n<line x1=\"352.8\" x2=\"352.8\" y1=\"62.0\" y2=\"197.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<text x=\"43.8\" y=\"85.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >\n0000\n </text>\n<line x1=\"45.8\" x2=\"52.8\" y1=\"85.0\" y2=\"85.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<rect x=\"52.8\" y=\"73.0\" width=\"250.00000000000003\" height=\"24\" id=\"bar_0_1650941668815691257\" fill=\"#5e7ce0\" />\n<text x=\"312.8\" y=\"85.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_0_1650941668815717802\" fill-opacity=\"0\" >\n25\n </text>\n<text x=\"43.8\" y=\"115.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >\n0100\n </text>\n<line x1=\"45.8\" x2=\"52.8\" y1=\"115.0\" y2=\"115.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<rect x=\"52.8\" y=\"103.0\" width=\"250.00000000000003\" height=\"24\" id=\"bar_1_1650941668815743983\" fill=\"#16acff\" />\n<text x=\"312.8\" y=\"115.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_1_1650941668815759390\" fill-opacity=\"0\" >\n25\n </text>\n<text x=\"43.8\" y=\"145.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >\n1000\n </text>\n<line x1=\"45.8\" x2=\"52.8\" y1=\"145.0\" y2=\"145.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<rect x=\"52.8\" y=\"133.0\" width=\"300.00000000000006\" height=\"24\" id=\"bar_2_1650941668815782860\" fill=\"#5e7ce0\" />\n<text x=\"362.80000000000007\" y=\"145.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_2_1650941668815805452\" fill-opacity=\"0\" >\n30\n </text>\n<text x=\"43.8\" y=\"175.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >\n1100\n </text>\n<line x1=\"45.8\" x2=\"52.8\" y1=\"175.0\" y2=\"175.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<rect x=\"52.8\" y=\"163.0\" width=\"200.00000000000003\" height=\"24\" id=\"bar_3_1650941668815828006\" fill=\"#16acff\" />\n<text x=\"262.8\" y=\"175.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_3_1650941668815842178\" fill-opacity=\"0\" >\n20\n </text>\n<animate xlink:href=\"#bar_0_1650941668815691257\" attributeName=\"width\" from=\"0\" to=\"250.00000000000003\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 250.00000000000003\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" />\n<animate xlink:href=\"#bar_1_1650941668815743983\" attributeName=\"width\" from=\"0\" to=\"250.00000000000003\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 250.00000000000003\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" />\n<animate xlink:href=\"#bar_2_1650941668815782860\" attributeName=\"width\" from=\"0\" to=\"300.00000000000006\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 300.00000000000006\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" />\n<animate xlink:href=\"#bar_3_1650941668815828006\" attributeName=\"width\" from=\"0\" to=\"200.00000000000003\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 200.00000000000003\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" />\n<animate xlink:href=\"#bar_2_1650941668815782860\" attributeName=\"fill\" from=\"#5e7ce0\" to=\"#fac209\" dur=\"0.15s\" calcMode=\"spline\" values=\"#5e7ce0; #fac209\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" />\n<animate xlink:href=\"#bar_text_0_1650941668815717802\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" />\n<animate xlink:href=\"#bar_text_1_1650941668815759390\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" />\n<animate xlink:href=\"#bar_text_2_1650941668815805452\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" />\n<animate xlink:href=\"#bar_text_3_1650941668815842178\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" />\n<text x=\"213.9\" y=\"41.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"middle\" >\nprobability\n </text>\n</svg></div>",
      "text/plain": [
       "<mindquantum.io.display.measure_res_svg_drawer.SVGMeasure at 0x7f61a45b3220>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pylint: disable=W0104\n",
    "sim = Simulator('projectq', circuit.n_qubits)  # 创建量子线路模拟器\n",
    "\n",
    "# 模拟线路100次，打印测量结果，随机种子seed设为100内的随机整数\n",
    "result = sim.sampling(circuit, shots=100, seed=np.random.randint(100))\n",
    "\n",
    "result.svg()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "从统计结果可以看出，最后寄存器1中只可能测出4个态，分别是$y=[0,4,8,12]$，这是由于$\\omega^{2\\pi iry/Q}\\ (Q=16)$当$y$取这四个值时恰好为1，而其它的态由于量子干涉导致概率幅抵消为零。把测量结果代入$\\frac{y}{Q}\\sim\\frac{c}{r}$，可以看出该式确实成立，我们有约50%的概率得到正确的周期$r$，但有约25%概率得到$r$的因数，还有25%概率得到0态，后两种情况需要重新计算。\n",
    "\n",
    "接下来构造的是通用的周期查找算法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def period_finder(N, a, q):\n",
    "    circuit = Circuit()  # 创建量子线路\n",
    "    register1 = range(q)  # 设置前q个比特为寄存器1\n",
    "    register2 = range(q, 2 * q)  # 设置后q个比特为寄存器2\n",
    "\n",
    "    circuit += UN(H, register1)  # 对寄存器1中的所有比特作用H门\n",
    "\n",
    "    # 对寄存器1做模乘运算，并将结果存入寄存器2，该操作由一个大的U门完成\n",
    "    circuit += U_operator(N, a, register1, register2)\n",
    "\n",
    "    circuit += qft(register1[::-1]).hermitian()  # 对寄存器1做傅立叶逆变换，须注意傅立叶变换作用的比特顺序，在这里需要反序\n",
    "    circuit.barrier()  # 添加barrier\n",
    "    circuit += UN(Measure(), register1)  # 测量寄存器1\n",
    "\n",
    "    sim = Simulator('projectq', circuit.n_qubits)  # 创建量子线路模拟器\n",
    "\n",
    "    # 模拟线路，收集测量结果，随机种子seed设为100内的随机整数\n",
    "    result = sim.sampling(circuit, seed=np.random.randint(100))\n",
    "\n",
    "    # result.data是一个字典，key是测量结果，value是出现频数，我们只做了一次采样，因此只有一个key, value必定为1\n",
    "    result = list(result.data.keys())[0]  # 将key取出\n",
    "    result = int(result, 2)  # 将结果从二进制转化为十进制\n",
    "\n",
    "    # 通过连分数分解法计算result/2**q逼近的不可约分数，分母不能大于N\n",
    "    eigenphase = float(result / 2**q)\n",
    "    f = Fraction.from_float(eigenphase).limit_denominator(N)\n",
    "    r = f.denominator  # 取f的分母，得到周期r\n",
    "\n",
    "    # r有可能是周期的因数，因此需要验证，当且仅当r是函数周期本身时返回r，否则返回None\n",
    "    if a**r % N == 1:\n",
    "        return r\n",
    "    return None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 经典计算机部分\n",
    "\n",
    "经典计算机部分负责将因数分解问题转化成寻找函数周期的问题，具体步骤如下：\n",
    "\n",
    "1. 随机取一个小于$N$的整数$a$，用gcd算法验证$a$与$N$是否互质，若$a$与$N$存在公因数，则直接得到$N$的一个因数，输出结果。\n",
    "\n",
    "2. 计算需要$q$个比特来存储$N$的二进制数。\n",
    "\n",
    "3. 用周期查找算法得到函数$f(x)=a^x\\ mod\\ N$的周期$r$。\n",
    "\n",
    "4. 判断$r$是否为偶数，若不是则回到第一步。\n",
    "\n",
    "5. 计算$a^{r/2}+1$和$a^{r/2}-1$，它们当中必有其一与$N$存在非1公因数。但是，$a^{r/2}+1$有可能可以整除$N$，因此最后输出结果仍有可能是$N$本身。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#pylint: disable=C0121,R1705\n",
    "def shor(N):\n",
    "    while True:\n",
    "        a = np.random.randint(N - 2) + 2  # 获得区间[2,N-1]内的随机整数a\n",
    "        b = np.gcd(a, N)  # 得到a与N的最大公因数b\n",
    "        if b != 1:\n",
    "            return b, int(N / b)  # 如果b不等于1，则b是N的质因数，返回分解结果\n",
    "\n",
    "        # 获得足够表示N的二进制的比特数q\n",
    "        q = 0\n",
    "        while True:\n",
    "            Q = 2**q\n",
    "            if Q >= N:\n",
    "                break\n",
    "            q += 1\n",
    "\n",
    "        r = period_finder(N, a, q)  # 使用周期查找算法得到r\n",
    "\n",
    "        # 判断r是否为偶数,若是则跳出循环，若不是则重新选择随机整数a\n",
    "        if r != None and r % 2 == 0:\n",
    "            break\n",
    "\n",
    "    # 计算a**(r/2)+1和a**(r/2)-1，并验证它们是否与N有公约数，若有则输出结果\n",
    "    c = np.gcd(a**(int(r / 2)) + 1, N)\n",
    "    d = np.gcd(a**(int(r / 2)) - 1, N)\n",
    "    if c != 1 and N % c == 0:\n",
    "        return c, int(N / c)\n",
    "    else:\n",
    "        return d, int(N / d)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "由于经典计算机模拟量子算法需要大量的内存，以及先前提到的MindQuantum中的模拟器暂时无法运行超过5比特的自定义门，因此我们暂时无法利用Shor算法计算$N>21$的情况。最后让我们试着用写好的Shor算法分解$N=15$。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Factoring N = p * q = 15\n",
      "p = 5\n",
      "q = 3\n"
     ]
    }
   ],
   "source": [
    "N = 15\n",
    "print(\"Factoring N = p * q =\", N)\n",
    "\n",
    "p, q = shor(N)\n",
    "print(\"p =\", p)\n",
    "print(\"q =\", q)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "从运行结果可以看到，我们成功的分解出15的两个质因数：3和5。\n",
    "\n",
    "至此，我们成功的使用MindQuantum实现了Shor算法。\n",
    "\n",
    "若想查询更多关于MindQuantum的API，请点击：[https://mindspore.cn/mindquantum/](https://mindspore.cn/mindquantum/)。"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "d62cf896b9ca57de08105ce3983377439eacacf6f6599f9150bf400edf4fa4b8"
  },
  "kernelspec": {
   "display_name": "MindSpore",
   "language": "python",
   "name": "mindspore"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "orig_nbformat": 2
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
